/*Diego Lima de Freitas RA: 317632
 *Yuri Souza Padua RA: 317420
 * 
 * Classe que trata os procedimentos
 */

package AST;

public class Procedure extends Subroutine {

    public Procedure(String name, Type type) {
        this.name = name;
        this.returnType = type;
    }

    public Procedure(String name) {
        this.name = name;
        this.returnType = null;
    }
    
    public void setNameMain(){
        this.name = "main";
    }

    @Override
    public void genC(PW pw) {
        if (this.returnType == null) {
            pw.out.print("void " + name + "(");
        } else {
            pw.out.print(this.returnType.getCname() + " " + this.name + "(");
        }

        if (paramList != null) {
            paramList.genC(pw);
        }
        pw.out.println(") {");
        pw.add();
        if (localVarList != null) {
            localVarList.genC(pw);
        }


        for (int i = 0; i < compositeCommand.getStatementList().size(); i++) {
            compositeCommand.getStatementList().get(i).genC(pw);
        }
        pw.sub();
        pw.out.println("}");
    }
}
